/*
 * Copyright 2009, Qys Creations 
 * 
 *  This file is part of Chameleon DB.
 *
 *  Chameleon DB is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Chameleon DB is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Chameleon DB.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * */



public class db_util {
	
	// misc
	
	public final static String DB_VERSION_IDENTIFIER = "QDB 0.1 ALPHA";
	public final static int DB_BYTE_LENGTH = 256;
	public final static int DB_TCP_PORT_NUMBER = 1108;
	public final static String DB_DATABASE_FILENAME_EXT = ".qdb";
	public final static String DB_DATABASE_LOGNAME_EXT = ".qlg";
	public final static String DB_DATABASE_FOLDER = "c:\\db\\databases\\";
	
	public final static int DB_NUMBER_OF_THREADS = 6;
	
	// Page size
	public final static int DB_PAGE_SIZE = 65536; //8192*4;
	
	// Page types
	public final static int DB_PAGE_TYPE_DATA_DEF = 0;
	public final static int DB_PAGE_TYPE_PARTION_DEF = 1;
	public final static int DB_PAGE_TYPE_TABLE_DEF = 2;
	public final static int DB_PAGE_TYPE_HEADER_DEF = 3;
	
	// When the result of a query is returned the first 4 bytes 
	// indicates the result message type using the following values:
	
	public final static int DB_RESULT_DATASET = 0;
	public final static int DB_RESULT_MESSAGE = 1;
	public final static int DB_RESULT_ERROR = 2;
	
	// The different data types are defined as: 
	
	public final static int DB_DATATYPE_INT = 1;
	public final static int DB_DATATYPE_INT_LENGTH = 4;
	public final static int DB_DATATYPE_VARCHAR= 2;
	public final static int DB_DATATYPE_VARCHAR_LENGTH = 128;
	public final static int DB_DATATYPE_COLUMN = 3;
	public final static int DB_DATATYPE_COLUMN_LENGTH = 256;

	// Compare operators
	public final static int DB_COMPARE_EQ = 1;
	public final static int DB_COMPARE_EQGT = 2;
	public final static int DB_COMPARE_EQLT = 3;
	public final static int DB_COMPARE_GT = 4;
	public final static int DB_COMPARE_LT = 5;
	
	// Table status codes
	public final static int DB_TABLE_STATUS_NORMAL = 0;
	public final static int DB_TABLE_STATUS_DELETED = 1;
	public final static int DB_TABLE_STATUS_LOCKED = 2;

	// Index status codes
	public final static int DB_INDEX_STATUS_NORMAL = 0;
	public final static int DB_INDEX_STATUS_DELETED = 1;
	public final static int DB_INDEX_STATUS_LOCKED = 2;
	
	// Row status codes
	public final static int DB_ROW_STATUS_NORMAL = 0;
	public final static int DB_ROW_STATUS_DELETED = 1;
	public final static int DB_ROW_STATUS_LOCKED = 2;
	
	// Message codes
	public final static int DB_MESSAGE_OK = 1;
	
	// Err codes
	public final static int DB_ERR_TABLE_NOT_FOUND = 1;
	public final static int DB_ERR_UNKNOWN_KEYWORDS = 2;
	public final static int DB_ERR_BAD_SQL_SYNTAX = 3;
	public final static int DB_ERR_COLUMN_NOT_FOUND = 4;
	public final static int DB_ERR_COL_VAL_NUMBER_MISMATCH = 5;
	public final static int DB_ERR_COL_TABLE_COL_MISMATCH = 6;
	public final static int DB_ERR_TABLE_ALLREADY_EXISTS = 7;
	public final static int DB_ERR_COLUMN_NAME_NOT_UNIQUE = 8;
	public final static int DB_ERR_TYPE_MISMATCH = 9;
	public final static int DB_ERR_CANNOT_INSERT_IDENTITY = 10;
	public final static int DB_ERR_INDEX_ALLREADY_EXISTS = 11;
	
	// For condition parts of statements
	public final static int DB_CONDITION_CONST_CONST = 0;
	public final static int DB_CONDITION_CONST_COL = 1;
	public final static int DB_CONDITION_COL_COL = 2;
	
	// Log action codes
	public final static long DB_LOG_WRITE = 1;
	
	// Magic values
	
	// This value should be computed for each created index.
	// Its the maximum number of values in each node in the B-tree
	public final static int DB_INDEX_SIZE = 60;
	
}
